<template>
	<div class="evidence-borrow-overlist-container">
		<el-table
			ref="multipleTable" border
			:data="tableData"
			:default-sort="{ prop: 'name', order: 'descending' }"
			:row-style="{ height: '37px' }"
			:cell-style="{ padding: '0' }"
			size="medium"
			style="width: 100%"
			:row-class-name="tableRowClassName"
		>
			<el-table-column align="center" label="序号" type="index" width="60"> </el-table-column>
			<el-table-column align="center" property="caseNo" sortable label="案件编号" show-overflow-tooltip />
			<el-table-column align="center" property="inspectionNo" sortable label="警情编号" show-overflow-tooltip />
			<el-table-column align="center" property="caseName" sortable label="案件名称" show-overflow-tooltip />
			<el-table-column align="center" property="caseTime" sortable label="案发时间" show-overflow-tooltip>
				<template #default="scope">
					{{ dateFormat(scope.row.caseTime) }}
				</template>
			</el-table-column>
			<el-table-column align="center" property="evidencePerson" sortable :label="outTypeTitle + '时间'" show-overflow-tooltip>
				<template #default="scope">
					{{ dateFormat(scope.row.activeTime) }}
				</template>
			</el-table-column>
			<el-table-column align="center" property="receiver" sortable :label="outTypeTitle + '人'" show-overflow-tooltip>
				<template #default="scope">
					{{ scope.row.activer }}
				</template>
			</el-table-column>
			<el-table-column align="center" property="evidenceName" sortable label="案卷名称" show-overflow-tooltip />

			<el-table-column align="center" property="activeStatusName" sortable :label="outTypeTitle + '状态'" show-overflow-tooltip />
			<el-table-column align="center" label="操作" width="200px">
				<template #default="scope">
					<el-button type="primary" @click="onBorrowInfo(scope.row)" plain size="mini">{{ outTypeTitle }}详情</el-button>
					<el-button type="success" @click="onDetailsInfo(scope.row)" plain size="mini">个案详情</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination
			:page-sizes="[10, 20, 50, 100]"
			:page-size="pager.pageSize"
			layout="prev, pager, next, jumper,total,sizes"
			:total="pager?.total"
			@size-change="onHandleSizeChange"
			@current-change="onHandleCurrentChange"
			prev-text="上一页"
			next-text="下一页"
			background
		>
		</el-pagination>
	</div>
</template>

<script lang="ts">
import { reactive, toRefs } from 'vue';
import { useRouter } from 'vue-router';
import { getOutType, dateFormat } from '/@/common/index';
import { useStore } from '/@/store/index';
import { queryImgs } from '/@/api/common/index';
import { GetTransfereEvidences } from '/@/api/evidence/transfere';
export default {
	name: 'BorrowOverList',
	props: {
		tableData: Object,
		outType: String,
		pager: Object,
	},
	setup(props: any, { emit }) {
		const router = useRouter();
		const store = useStore();
		const state = reactive({
			outTypeTitle: getOutType(props.outType),
			tableData: props.tableData,
			outType: props.outType,
			pager: props.pager,
		});
		//借调详情
		const onBorrowInfo = async (row: any) => {
			let _type = 11;
			if (row.evidenceStatus == 1) _type = 10;
			await Promise.all([queryImgs(row.deliveryNo, _type), GetTransfereEvidences(row.transfereId)]).then((res) => {
				const _data = res[1];
				row.imgs = res[0].data;
				row.saveSignImg = row.imgs.find((x) => x.type == 6)?.url;
				row.signImg = row.imgs.find((x) => x.type == 4 || x.type == 5)?.url;
				store.dispatch('customs/setCustoms', {
					selectionEvidences: _data.data.map((x: any) => {
						return {
							no: x.evidenceNo,
							name: x.evidenceName,
							quantity: x.evidenceQuntity,
							source: x.source,
							extractionParts: x.extractionParts,
							extractionPersonName: x.extractionPersonName,
							extractionDateTime: x.extractionDateTime,
							extractMethod: x.extractMethod,
							status: 1,
							location: x.location,
							evidenceShape: x.evidenceShape,
							transfereNo: x.transfereNo,
						};
					}),
					transfereInfo: _data.data[0],
					formInline: row,
					deliveryNo: row.deliveryNo,
				});
				router.getRoutes().find((x) => x.name == 'EvidenceCommonDetail').title = state.outTypeTitle + '确认';
				router.getRoutes().find((x) => x.name == 'EvidenceCommonDetail').meta.title = state.outTypeTitle + '确认';
				router.push({ path: '/evidence/common/detail', query: { outType: props.outType } });
			});
		};
		//个案详情
		const onDetailsInfo = (row: any) => {
			router.push({
				path: '/evidence/unit/details',
				query: { caseid: row.id },
			});
		};
		const tableRowClassName = (row: any, rowIndex: number) => {
			if (rowIndex === 1) {
				return 'warning-row';
			} else if (rowIndex === 3) {
				return 'success-row';
			}
			return '';
		};
		function onHandleSizeChange(pageSize: number) {
			state.pager.pageSize = pageSize;
			emit('reload');
		}
		function onHandleCurrentChange(pageIndex: any) {
			state.pager.page = pageIndex;
			emit('reload');
		}
		return {
			tableRowClassName,
			onBorrowInfo,
			onHandleSizeChange,
			onHandleCurrentChange,
			onDetailsInfo,
			dateFormat,
			...toRefs(state),
		};
	},
};
</script>
